const Storage = require("../../utils/storage.js");
const session = require("../../utils/session.js");
const utils = require("../../utils/utils.js");
const toast = require("../../utils/toasts.js");
const com = require("../../utils/commonRequest.js");
const biz = require("../../utils/bizUtils.js");
const cart = require("../../utils/cart.js");
import {
  req,
} from "../../utils/api.js";
const wxm = require("../../utils/wechat_modules.js");

const api = require("../../utils/api.js");
const app = getApp();
const globalData = app.globalData;

Page({
  data: {
    favList: [],
    viewList: [],
    isShowLoginModal: false,
    isShowBindPhoneModal: true,
    banners: ['https://img.lingxing.site/jx/jx_banner3_1.png', 'https://img.lingxing.site/jx/banner_600_2_1.png'],
    menus: [{
      'title': '立即报名',
      'subTitle': 'ORDER NOW',
      'icon': '/images/order_now_icon.png',
      'tip': '2000拿驾照',
      click: 'gotoProductList'
    }, {
      'title': '在线学车',
      'subTitle': 'ONLINE STUDY',
      'icon': '/images/online_icon1.png',
      click: 'gotoOnlineStudy'
    }, {
      'title': '附近驾校',
      'subTitle': 'NEARBY SCHOOL',
      'icon': '/images/near_by_icon.png',
      click: 'gotoSellerList'
    }, {
      'title': '上路陪练',
      'subTitle': 'ROAD TRAIN',
      'icon': '/images/road_train_icon.png',
      'tip': '敬请期待',
    }
    // , {
    //   'title': '2k优势',
    //   'subTitle': 'OUR ADVANTAGES',
    //   'icon': '/images/adv_icon.png'
    // }
    ],
    applogo: globalData.applogo,
    isIphoneX: globalData.isIphoneX,
  },
  onLoad: function() {
    // toast.showLoading();
    session.login(this.refreshMe);
  },
  refreshMe: function(usr) {
    this.setData({
      user: usr
    });
    cart.updateCount();
    this.showFavXcx();
  },
  onShow: function() {
  },
  refresh: function() {
  },
  // 获取当前用户信息
  getUserInfo: function() {
    session.getUser(this);
  },
  showLoginModal: function() {
    this.setData({
      isShowLoginModal: true
    });
  },
  closeLogin: function() {
    session.getUser(this);
    this.setData({
      isShowLoginModal: false
    });
  },
  onShareAppMessage: function(res) {
    return wxm.commonShare(this);
  },
  hideShare: function() {
    this.setData({
      showShareImg: false
    });
  },
  pushFormSubmit: function(e) {
    console.log(e);
    console.log("formId:" + e.detail.formId);
    com.saveFormId(e);
  },
  banners: function() {
    // com.banners(this);
  },
  showFavXcx: function() {
    var that = this;
    var showFavXcx = wx.getStorageSync("showFavXcx");
    if (showFavXcx && showFavXcx.value) {
      return;
    }

    Storage.set("showFavXcx", true, 24 * 60 * 60 * 5);

    this.setData({
      showFavXcx: true
    });

    setTimeout(function() {
      that.setData({
        showFavXcx: false
      })
    }, 3000);
  },
  gotoSellerList: function() {
    wx.navigateTo({
      url: '/pages/sellerList/sellerList',
    })
  },
  gotoProductList: function() {
    wx.navigateTo({
      url: '/pages/productList/productList',
    })
  },
  gotoOnlineStudy:function() {
    wx.navigateTo({
      url: '/pages/questionList/questionList',
    })
  }
});